﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IHISCETeim.DAL;
using IHISCETeim.Model;
using IHISCETeim.Library;
using System.Data;
namespace IHISCETeim.BLL
{
    public class UAgentMacStockController : BaseController
    {
        public static bool Add(UAgentMacStockInfo obj)
        {
            return UAgentMacStockDAL.Add(obj);
        }
        public static bool Delete(int UASID)
        {
            return UAgentMacStockDAL.Delete(UASID);
        }
        public static UAgentMacStockInfo GetById(int UASID)
        {
            return  CBO.FillObject<UAgentMacStockInfo>( UAgentMacStockDAL.GetById(UASID));
        }
        public static DataTableCollection GetPagination(string sqlwhere,int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            return UAgentMacStockDAL.GetPagination(sqlwhere, PageIndex, PageSize, Sort, ref  TotalCount);
        }
        public static bool Update(UAgentMacStockInfo obj)
        {
            return UAgentMacStockDAL.Update(obj);
        }
        /// <summary>
        /// 获取所有代理商的样机数量,只显示未出库的
        /// </summary>
        /// <returns></returns>
        public static DataTable GetMacStockList()
        {
            return UAgentMacStockDAL.GetMacStockList();
        }

        public static bool UAgentMacStockDetail_Add(UAgentMacStockDetailInfo obj)
        {
            return UAgentMacStockDAL.UAgentMacStockDetail_Add(obj);
        }
        public static List<UAgentMacStockDetailInfo> UAgentMacStockDetail_GetALLByUASID(int UASID)
        {
            return CBO.FillCollection<UAgentMacStockDetailInfo>( UAgentMacStockDAL.UAgentMacStockDetail_GetALLByUASID(UASID));
        }

        public static UAgentMacStockDetailInfo UAgentMacStockDetail_GetByUASDID(int UASID,int UASDID)
        {
            List<UAgentMacStockDetailInfo> all = UAgentMacStockDetail_GetALLByUASID(UASID);
            return all.FirstOrDefault<UAgentMacStockDetailInfo>(e => e.UASDID == UASDID);
        }

        public static bool UAgentMacStockDetail_Delete(int UASDID)
        {
            return UAgentMacStockDAL.UAgentMacStockDetail_Delete(UASDID);
        }
        /// <summary>
        /// 点检完成报表中，用于获取经销商一段时间内已点检的列表
        /// </summary>
        /// <param name="AgentName"></param>
        /// <param name="fromdate"></param>
        /// <param name="todate"></param>
        /// <returns></returns>
        public static DataTableCollection UAgentMacStockDetail_GetAllCheckList(string AgentName, string fromdate, string todate)
        {
            return UAgentMacStockDAL.UAgentMacStockDetail_GetAllCheckList(AgentName, fromdate, todate);
        }

        #region 2014-11-18 新机入库检查
        /// <summary>
        /// 新机入库验收检查模板表
        /// </summary>
        /// <returns></returns>
        public static List<UAgentMacNewTempleteInfo> UAgentMacNewTemplete_GetAll()
        {
            List<UAgentMacNewTempleteInfo> allTemp=DC.Get<List<UAgentMacNewTempleteInfo>>(AgentMacNewTempleteKey);
            if (allTemp == null)
            {
                allTemp =CBO.FillCollection<UAgentMacNewTempleteInfo>( UAgentMacStockDAL.UAgentMacNewTemplete_GetAll());
                DC.Add(AgentMacNewTempleteKey, allTemp);
            }
            return allTemp;

        }
        /// <summary>
        /// 新增样机入库及NG项
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="listNG"></param>
        /// <returns></returns>
        public static int UAgentMacNewNG_Add(UAgentMacStockInfo obj, List<UAgentMacNewNGInfo> listNG)
        {
            return UAgentMacStockDAL.UAgentMacNewNG_Add(obj, listNG);
        }

        public static bool UAgentMacNewNG_Update(UAgentMacStockInfo obj, List<UAgentMacNewNGInfo> listNG)
        {
            return UAgentMacStockDAL.UAgentMacNewNG_Update(obj, listNG);
        }
        public static bool UAgentMacStock_UpdateOut(int UASID,bool state,string outdate)
        {
            return UAgentMacStockDAL.UAgentMacStock_UpdateOut(UASID, state, outdate);
        }
        public static List<UAgentMacNewNGInfo> UAgentMacNewNG_GetByUASID(int UASID)
        {
             return CBO.FillCollection<UAgentMacNewNGInfo>( UAgentMacStockDAL.UAgentMacNewNG_GetByUASID(UASID));
        }
        #endregion

        #region 新机入库检查报表
        /// <summary>
        /// 新机入库检查品质统计表
        /// </summary>
        /// <param name="sqlwhere"></param>
        /// <returns></returns>
        public static DataTable UAgentMacNewNG_GetNGTotalReport(string sqlwhere)
        {
            return UAgentMacStockDAL.UAgentMacNewNG_GetNGTotalReport(sqlwhere);
        }
        /// <summary>
        /// 新机入库检查品质统计表，获取一个项的所对应的明细
        /// </summary>
        /// <param name="sqlwhere"></param>
        /// <returns></returns>
        public static DataTable UAgentMacNewNG_GetNGTotalReportDetail(string sqlwhere)
        {
            return UAgentMacStockDAL.UAgentMacNewNG_GetNGTotalReportDetail(sqlwhere);
        }

        public static DataTable UMacKeep_GetKeepTimeReport(string sqlwhere)
        {
            return UAgentMacStockDAL.UMacKeep_GetKeepTimeReport(sqlwhere);
        }
        #endregion

        #region 2014-12-2 样机定期检查
        /// <summary>
        /// 样机定期检查模板
        /// </summary>
        /// <returns></returns>
        public static List<UAgentMacStockDetailTempleteInfo> UAgentMacStockDetailTemplete_GetAll()
        {
            List<UAgentMacStockDetailTempleteInfo> allTemp = DC.Get<List<UAgentMacStockDetailTempleteInfo>>(AgentMacStockDetailTempleteKey);
            if (allTemp == null)
            {
                allTemp = CBO.FillCollection<UAgentMacStockDetailTempleteInfo>(UAgentMacStockDAL.UAgentMacStockDetailTemplete_GetAll());
                DC.Add(AgentMacStockDetailTempleteKey, allTemp);
            }
            return allTemp;
        }

        public static List<UAgentMacStockDetailNGInfo> UAgentMacStockDetailNG_GetAllByUASDID(int UASDID)
        {
            return CBO.FillCollection<UAgentMacStockDetailNGInfo>(UAgentMacStockDAL.UAgentMacStockDetailNG_GetAllByUASDID(UASDID));
        }
        public static string UAgentMacStockDetailNG_Add(UAgentMacStockDetailInfo obj, List<UAgentMacStockDetailNGInfo> listNG)
        {
            return UAgentMacStockDAL.UAgentMacStockDetailNG_Add(obj, listNG);
        }

        public static string UAgentMacStockDetailNG_Update(UAgentMacStockDetailInfo obj, List<UAgentMacStockDetailNGInfo> listNG)
        {
            return UAgentMacStockDAL.UAgentMacStockDetailNG_Update(obj, listNG);
        }
        #endregion

    }
}
